package com.mvp.shq.washer.ui.news;

import com.mvp.shq.washer.entity.result.BaseResult;
import com.mvp.shq.washer.entity.result.MsgResult;
import com.mvp.shq.washer.http.BaseObserver;
import com.mvp.shq.washer.utils.SpUtil;
import com.orhanobut.logger.Logger;

/**
 * Created by Administrator on 2017/8/24.
 */

public class NewsPresenter extends NewsConstract.Presenter {
    @Override
    public void onStart() {
    }

    @Override
    void getMsgs(int pageNo,int pageSize) {
        String token = SpUtil.getToken();
        String userId = SpUtil.getUser().getId();
        model.getMessages(token,userId,pageNo,pageSize)
                .subscribe(new BaseObserver<MsgResult>(view) {
                    @Override
                    protected void onSuccees(BaseResult<MsgResult> t) throws Exception {
                        if (t.isError()){
                            view.msgFail(t.getMsg());
                        }else {
                            view.msgSuccess(t.getData().getList());
                        }
                    }

                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                        view.msgFail("未知错误");
                        Logger.e("-------------------------------------------");
                        e.printStackTrace();
                        Logger.e("-------------------------------------------");
                    }
                });
    }
}
